import Item from "antd/es/list/Item";
import React from "react";
export const menuData = [
    {
        key: `k01`,
        label: `安全管理`,
        title: '安全管理',
        children: [
            {
                key: "/Main/dangerManagement",
                label: `隐患管理`,
                title: '隐患管理',
            },
            {
                key: "/Main/safetyInspection",
                label: `安全巡查`,
                title: '安全巡查',
            }, {
                key: "/Main/Escort",
                label: `护导管理`,
                title: '护导管理',
            }, {
                key: "/Main/Visitor",
                label: `访机客管理`,
                title: '访机客管理',
            },
        ]
    },
    {
        key: `k02`,
        label: `考勤管理`,
        title: '考勤管理',

        children: [
            {
               
                label: `学生考勤`,
                title: '学生考勤',

            },
            {
                key: "/Main/Leave",
                label: `教师考勤`,
                title: '教师考勤',

            }
        ]
    },
    {
        key: `k03`,
        label: `学生管理`,
        title: '学生管理',

        children: [
            {
                key: "/Main/studentManagement",
                label: `学生管理`,
                title: '学生管理',

            },

        ]
    },
    {
        key: `k04`,
        label: `教职工管理`,
        title: '教职工管理',

        children: [
            {
                key: "/Main/workerManagement",
                label: `职工管理`,
                title: '职工管理',


            },
            {
                key: "/Main/teacherManagement",
                label: `教师管理`,
                title: '教师管理',

            }, {
                key: "/Main/classTeacher",
                label: `班主任管理`,
                title: '班主任管理',

            }, {
                key: "/Main/classManagement",
                label: `班级管理`,
                title: '班级管理',

            }, {
                key: "/Main/SecurityStaff",
                label: `保安管理`,
                title: '保安管理',

            },

        ]
    },
    {
        key: `k05`,
        label: `权限管理`,
        title: '权限管理',

        children: [
            {
                key: "/Main/myRole",
                label: `角色管理`,
                title: '角色管理',

            },
            {
                key: "/Main/Department",
                label: `部门管理`,
                title: '部门管理',

            }, {
                key: "/Main/Account",
                label: `账号管理`,
                title: '账号管理',

            },

        ]
    }, {
        key: `k06`,
        label: `添加角色`,
        title: '添加角色',
        children: [
            {
                key: '/Main/addAdmin',
                label: '角色添加',
                title: '角色添加',



            }
        ]



    }



]
// 获取当前的菜单数据（动态菜单）
// 根据当前用户的权限，在所有菜单数据中过滤出当前用户的菜单
export const getCurrentMenu = () => {
    // 1、获取该用户的权限
    // let checkedKeys = JSON.parse(sessionStorage.getItem("grants"));

    let checkedKeys = [];

    if (sessionStorage.getItem('grants')) {
        checkedKeys = JSON.parse(sessionStorage.getItem('grants'))
    }

    let currMenus = [];

    menuData.forEach(item => {
        //处理第一级菜单
        if (checkedKeys.some(m => m == item.key)) {
            currMenus.push({ ...item });

            //处理第二级菜单 
            if (item.children && Array.isArray(item.children)) {

                let arr = [];

                item.children.forEach(sonItem => {
                    if (checkedKeys.some(m => m == sonItem.key)) {
                        let obj = { ...sonItem };
                        obj.children = undefined;
                        arr.push(obj);
                        // 处理crud：
                        if (sonItem.children) {
                            obj.crud = "";
                            for (let i = 0; i < sonItem.children.length; i++) {
                                obj.crud += checkedKeys.some(m => m == sonItem.children[i].key) ? "1" : "0"
                            }
                        }
                    }
                })
                currMenus[currMenus.length - 1].children = arr;
            }
        }
    })

    console.log("currMenus", currMenus);
    return currMenus;


}
